package com.goldcn.order.controller;

import com.goldcn.order.dto.BranchReportFormDto;
import com.goldcn.order.dto.GoodsReportDto;
import com.goldcn.order.dto.MemberReportDto;
import com.goldcn.order.service.GoodsReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zll on 2017/4/14.
 */
@Api(value = "商品-订单报表")
@RestController
@RequestMapping(value = "/orderGoodsStatistics")
public class OrderGoodsReportController {
    @Autowired
    GoodsReportService goodsReportService;


    //部门报表接口
    @ApiOperation(value = "商品首页-柱状图以及数量")
    @RequestMapping(value="/overViewGoodsGra",method = RequestMethod.POST)
    public Object firSaleView(@RequestBody GoodsReportDto goodsReportDto) {
        Map<String,Object> resultMap = new HashMap<>();
        goodsReportDto.setOrderByField("orderQty");
        goodsReportDto.setIsAsc("0");
        goodsReportDto.setPageNo(1);
        goodsReportDto.setPageSize(10);
        Object departQtyGra = goodsReportService.getAllGoodsReport(goodsReportDto);
        goodsReportDto.setOrderByField("transactionTotal");
        Object departAmountGra = goodsReportService.getAllGoodsReport(goodsReportDto);
        resultMap.put("departQtyGra",departQtyGra);
        resultMap.put("departAmountGra",departAmountGra);
        resultMap.put("allCounts",goodsReportService.getOnSalesCounts());
        return resultMap;
    }


//    //部门报表接口
//    @ApiOperation(value = "商品首页-柱状图以及数量")
//    @RequestMapping(value="/overViewGoodsGra",method = RequestMethod.POST)
//    public Object departSaleView(@RequestBody GoodsReportDto goodsReportDto) {
//        Map<String,Object> resultMap = new HashMap<>();
//        goodsReportDto.setOrderByField("orderQty");
//        goodsReportDto.setIsAsc("0");
//        goodsReportDto.setPageNo(1);
//        goodsReportDto.setPageSize(10);
//        Object departQtyGra = goodsReportService.getAllGoodsReport(goodsReportDto);
//        goodsReportDto.setOrderByField("transactionTotal");
//        Object departAmountGra = goodsReportService.getAllGoodsReport(goodsReportDto);
//        resultMap.put("departQtyGra",departQtyGra);
//        resultMap.put("departAmountGra",departAmountGra);
//        resultMap.put("allCounts",goodsReportService.getOnSalesCounts());
//        return resultMap;
//    }

    //商品销售总览数据
    @ApiOperation(value = "商品销售总览数据")
    @RequestMapping(value="/overViewGoodsSales",method = RequestMethod.POST)
    public Object saleView(@RequestBody GoodsReportDto goodsReportDto) {
        return goodsReportService.getAllGoodsReport(goodsReportDto);
    }

    //支部报表接口
    @ApiOperation(value = "部门订单-商品数据报表")
    @RequestMapping(value="/headerGoodsSales",method = RequestMethod.POST)
    public Object branchPort(@RequestBody BranchReportFormDto branchReportFormDto) {
        return goodsReportService.getOrderListPortHeader(branchReportFormDto);
    }


    //支部报表接口
    @ApiOperation(value = "分部订单-商品数据统计")
    @RequestMapping(value="/branchGoodsSales",method = RequestMethod.POST)
    public Object memberReport(@RequestBody BranchReportFormDto branchReportFormDto) {
        return goodsReportService.getOrderListBranch(branchReportFormDto);
    }


    @ApiOperation(value = "销售经理订单-商品数据统计")
    @RequestMapping(value="/memberGoodsSales",method = RequestMethod.POST)
    public Object memberReport(@RequestBody MemberReportDto memberReportDto) {
        return goodsReportService.getMemberSalesReport(memberReportDto);
    }

    //支部报表接口
    @ApiOperation(value = "部门订单-本部商品数据报表")
    @RequestMapping(value="/headerGoodsSalesSelf",method = RequestMethod.POST)
    public Object branchPort(@RequestBody MemberReportDto memberReportDto  ) {
        return goodsReportService.getOrderListPortHeaderSelf(memberReportDto);
    }


    @ApiOperation(value = "商品销售规格明细数据")
    @RequestMapping(value="/overViewGoodsBySku",method = RequestMethod.POST)
    public Object saleViewByGoodsSku(@RequestBody GoodsReportDto goodsReportDto) {
        return goodsReportService.getGoodsSkuReportGoodsId(goodsReportDto);
    }


    @ApiOperation(value = "根据名字查询销售经理订单-商品数据统计")
    @RequestMapping(value="/saleGoodsReportByName",method = RequestMethod.POST)
    public Object saleGoodsReportByName(@RequestBody MemberReportDto memberReportDto) {
        return goodsReportService.saleGoodsReportByName(memberReportDto);
    }

    @ApiOperation(value = "导出,主页商品销售总览数据,按商品分统计")
    @RequestMapping(value="/export/overViewGoodsSales",method = RequestMethod.POST)
    public Object saleViewExport(@RequestBody GoodsReportDto goodsReportDto) {
        return goodsReportService.getAllGoodsReportExport(goodsReportDto);
    }


    @ApiOperation(value = "导出,部门订单(本部、分部、二级分部)-商品数据报表")
    @RequestMapping(value="/export/headerGoodsSales",method = RequestMethod.POST)
    public Object branchPortExport(@RequestBody BranchReportFormDto branchReportFormDto) {
        return goodsReportService.getOrderListPortHeaderExport(branchReportFormDto);
    }

    @ApiOperation(value = "导出,（员工销售排名）销售经理订单-商品数据统计")
    @RequestMapping(value="/export/memberGoodsSales",method = RequestMethod.POST)
    public Object memberReportExport(@RequestBody MemberReportDto memberReportDto) {
        return goodsReportService.getMemberSalesReportExport(memberReportDto);
    }

    //总行本部报表接口
    @ApiOperation(value = "导出，部门订单-（总行、分部额、二级分部）本部商品数据报表")
    @RequestMapping(value="/export/headerGoodsSalesSelf",method = RequestMethod.POST)
    public Object branchPortExport(@RequestBody MemberReportDto memberReportDto  ) {
        return goodsReportService.getOrderListPortHeaderSelfExport(memberReportDto);
    }

    //支部报表接口
    @ApiOperation(value = "(支部销售排名)分部订单-商品数据统计")
    @RequestMapping(value="/export/branchGoodsSales",method = RequestMethod.POST)
    public Object memberReportExport(@RequestBody BranchReportFormDto branchReportFormDto) {
        return goodsReportService.getOrderListBranchExport(branchReportFormDto);
    }
}
